package com.qding.park.manager.timer.schedule.job;

import java.util.Date;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobExecutionContext;
import org.quartz.JobKey;
import org.springframework.stereotype.Service;

import com.baidu.disconf.client.common.annotations.DisconfUpdateService;
import com.baidu.disconf.client.common.update.IDisconfUpdate;
import com.qding.park.common.core.cache.service.CacheServiceFacade;
import com.qding.park.common.core.constant.CacheKeyThree;
import com.qding.park.common.core.redis.JedisClient;
import com.qding.park.common.core.redis.SerializeUtils;
import com.qding.park.manager.pojo.TbCarlock;
import com.qding.park.manager.pojo.TbReserve;
import com.qding.park.manager.pojo.queue.QueueMsg;
import com.qding.park.manager.pojo.queue.QueueTypeEnum;
import com.qding.park.manager.timer.ParkTimerApplication;
import com.qding.park.manager.timer.conf.TaskConfig;

/**
 * @ClassName ReserveCheckJob
 * @Description TODO(失败任务重做)
 * @author Administrator
 * @Date 2016年9月15日 下午3:53:58
 * @version 1.0.0
 */
@Service
@DisconfUpdateService( classes={TaskConfig.class},itemKeys = { "task.FailTaskRedoJob.name" ,"task.FailTaskRedoJob.taskJobClass","task.FailTaskRedoJob.cronTime"})
public class FailTaskRedoJob extends AbstractJob implements IDisconfUpdate{
	private static final Log _log = LogFactory.getLog(FailTaskRedoJob.class);

	@Override
	public void execJob(JobExecutionContext context) {
		JobKey jobKey = context.getJobDetail().getKey();
		
		CacheServiceFacade cacheServiceFacade = ParkTimerApplication.ctxUtil.getApplicationContext()
				.getBean(CacheServiceFacade.class);
		
		//失败任务重做
		QueueMsg  msg=new QueueMsg();
		msg.setEventType(QueueTypeEnum.FAILTASK_REDO.getType());
		
		cacheServiceFacade.msg_queue_push(msg);
		
		try {
			Thread.sleep(1000*60*5);
		} catch (InterruptedException e) {
			_log.error(e, e);
		}
		_log.info("失败任务重做: " + jobKey + " executing at " + new Date());

	}

	@Override
	public void reload() throws Exception {
		_log.info(TaskConfig.getTask_FailTaskRedoJob_name());
		String taskName=TaskConfig.getTask_FailTaskRedoJob_name();
		String cronTime=TaskConfig.getTask_FailTaskRedoJob_cronTime();
		super.reloadTask(taskName,cronTime);
		
	}
}
